<?php

/**
 *   52zll.top
 */

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

if($ac == 'add_comment'){
	
	if($_GET['formhash'] != $_G['formhash']) {
		echo json_encode(array('id' => 0));
		exit;
	}
	
	$setarr = array(
		'message' => $_GET['content'],
		'id' => $_GET['identify'],
		'uid' => $_G['uid'],
		'username' => $_G['username'],
		'dateline' => $_G['timestamp'],
		'ip' => $_G['clientip'],
	);
	
	if($type == 'graphic'){
		$setarr['table'] = 'dzapp_zhibo_graphic';
	}else{
		$setarr['table'] = 'dzapp_zhibo_activity';
	}
	
	$common_id = C::t('#dzapp_zhibo#dzapp_zhibo_comment')->insert($setarr, true);
	echo json_encode(array('id' => $common_id, 'avatar' => get_avatar($_G['uid']), 'username' => diconv($_G['username'], CHARSET, 'UTF-8'), 'message' => diconv($_GET['content'], CHARSET, 'UTF-8'), 'dateline' => gmdate("Y-m-d H:i:s", $_G['timestamp'])));
	exit;
	
} elseif($ac == 'new_comment'){

	$param = array(
		array('id', $_GET['identify']),
		array('dateline', $_G['timestamp'] - 3, '>='),
	);
	$query = C::t('#dzapp_zhibo#dzapp_zhibo_comment')->fetch_all_by_search($param);
	$list = array();
	foreach($query as $value) {
		$value['avatar'] = get_avatar($value['uid']);
		$value['message'] = diconv($value['message'], CHARSET, 'UTF-8');
		$value['username'] = diconv($value['username'], CHARSET, 'UTF-8');
		$value['dateline'] = gmdate("Y-m-d H:i:s", $value['dateline']);
		$list[] = $value;
	}
	
	echo json_encode($list); exit;
	
}elseif ($ac == 'praise'){
	
	if($_GET['formhash'] == $_G['formhash']) {
		C::t('#dzapp_zhibo#dzapp_zhibo_activity')->increase($_GET['activity_id'], array('praise'=>1));
	}
	
} elseif ($ac == 'comment'){
	
	$perpage = $var['perpage'] ? $var['perpage'] : 10;
	$page = max(1, intval($_GET['page']));
	$start = ($page - 1) * $perpage;
	if($start < 0) $start = 0;
	
	$param = array(
		array('id', $_GET['identify']),
	);
	$query = C::t('#dzapp_zhibo#dzapp_zhibo_comment')->fetch_all_by_search($param, $start, $perpage);
	$list = array();
	foreach($query as $value) {
		$value['avatar'] = get_avatar($value['uid']);
		$value['message'] = diconv($value['message'], CHARSET, 'UTF-8');
		$value['username'] = diconv($value['username'], CHARSET, 'UTF-8');
		$value['dateline'] = gmdate("Y-m-d H:i:s", $value['dateline']);
		$list[] = $value;
	}
	
	echo json_encode($list); exit;
		
}elseif($ac == 'graphic'){
	
	$perpage = $var['perpage'] ? $var['perpage'] : 10;
	$page = max(1, intval($_GET['page']));
	$start = ($page - 1) * $perpage;
	if($start < 0) $start = 0;
	
	$param = array(
		array('activity_id', $_GET['identify']),
	);
	$list = array();
	$query = C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->fetch_all_by_search($param, $start, $perpage);
	foreach($query as $value) {
		$value['avatar'] = get_avatar($value['uid']);
		$value['dateline'] = gmdate("Y-m-d", $value['dateline']);
		$value['describe'] = diconv($value['describe'], CHARSET, 'UTF-8');
		$value['username'] = diconv($value['username'], CHARSET, 'UTF-8');
		$value['pic'] = $value['pic'] ? dzapp_pic_get($value['pic'], 'portal', 0, $_G['setting']['ftp']['on']) : 'static/image/common/nophoto.gif';
		$list[] = $value;
	}
	
	echo json_encode($list); exit;
	
}elseif($ac == 'upload'){
	
	if($_GET['formhash'] != $_G['formhash']) {
		echo '';exit;
	}
	
	if($pic = dzapp_pic_upload($_FILES['pic'], 'portal', 320, 240)) $_GET['pic'] = $pic['pic'];
	echo $_GET['pic'];exit;
	
}elseif($ac == 'save'){
	
	if($_GET['formhash'] != $_G['formhash']) {
		echo '0';exit;
	}
	
	$activity = C::t('#dzapp_zhibo#dzapp_zhibo_activity')->fetch($_GET['activity_id']);
	$manager = array_filter(explode(',', $activity['manager']));
	$config['manager'] = explode(',', $config['manager']);
	$manager = array_merge($manager, $config['manager']);
	
	if(!in_array($_G['username'], $manager)){
		echo '0';exit;
	}
	
	$setarr = array(
		'pic' => $_GET['pic'],
		'describe' => diconv($_GET['describe'], 'UTF-8', CHARSET),
		'activity_id' => $_GET['activity_id'],
		'dateline' => $_G['timestamp'],
		'uid' => $_G['uid'],
		'username' => $_G['username'],
	);
	C::t('#dzapp_zhibo#dzapp_zhibo_graphic')->insert($setarr);
	$pic = $_GET['pic'] ? dzapp_pic_get($_GET['pic'], 'portal', 0, $_G['setting']['ftp']['on']) : 'static/image/common/nophoto.gif';
	$dateline= gmdate("Y-m-d H:i:s", $_G['timestamp']);
	
	echo json_encode(array('status' => 1, 'pic' => $pic, 'username' => diconv($_G['username'], CHARSET, 'UTF-8'), 'avatar' => get_avatar($_G['uid']),'dateline' => $dateline, 'describe' => $_GET['describe']));exit;
}else{
	
}
//From:www_caogen8_co
?>